<template>
  <view class="deviceInfo">
    <o-cell border card>
        <o-cell-item :title="'设备名称:'+deviceDetail.equipmentName" @tap="gotoDeviceDetail" arrow/>
        <o-cell-item :title="'设备编码:'+deviceDetail.equipmentNo" arrow/>
        <o-cell-item :title="'设备类型:'+equipmentTypeName" arrow />
        <o-cell-item :title="'所属用户:'+deviceDetail.user.nickName" arrow />
        <o-cell-item :title="'控制板版本:'+controlPanelVesion" arrow />
        <o-cell-item :title="'上位机软件版本:'+upperComputerVesion" arrow />
    </o-cell>
    <view>
    			<!-- 输入框示例 -->
    			<uni-popup ref="inputDialog" type="dialog">
    				<uni-popup-dialog ref="inputClose"  mode="input" title="设备名称"  placeholder="请输入设备名称" @confirm="dialogInputConfirm">
              <view>
             <uni-easyinput type="text"
                          v-model="equipmentName"
                          :placeholder="placeholder"/>
                    </view>
              </uni-popup-dialog>
    			</uni-popup>
    		</view>
  </view>
</template>

<script>
  import {getEquipment,updateEquipment} from '@/api/system/equiment/equipment.js'
  export default {
    data() {
      return {
         deviceDetail:'',
         equipmentTypeName:'',
         equipmentName:'',
         equipmentNo:uni.getStorageSync("equipmentNo"),
         type: 'center',
         controlPanelVesion:uni.getStorageSync("controlPanelVesion"),
         upperComputerVesion:uni.getStorageSync("upperComputerVesion")
      }
    },
    onShow() {
      this.getEquipmentDetaile()
    },
    methods: {
      getEquipmentDetaile:async function(){
        const res = await getEquipment(this.equipmentNo);
        if(res.code ==200){
          this.deviceDetail=res.data
          this.equipmentTypeName=res.data.mkEquipmentType==null?'':res.data.mkEquipmentType.equipmentTypeName
        }
      },
      //点击弹出输入框
      gotoDeviceDetail(){
        this.$refs.inputDialog.open()
        this.equipmentName =this.deviceDetail.equipmentName
      },
      //点击确定输入框
      dialogInputConfirm:async function(val){
        if(this.equipmentName == null || this.equipmentName == ''){
           this.$modal.msgError("名称不能为空");
        }else{
          const data ={
              equipmentNo:this.equipmentNo,
              equipmentName:this.equipmentName
            }
          const res = await updateEquipment(data);
          if(res.code == 200){
           this.getEquipmentDetaile()
           this.$modal.msgSuccess("修改成功");
           this.$refs.inputDialog.close()
            }
        }
      }
    },
   }
</script>

<style>
  page{
    background-color: #f9f9f9;
  }
</style>